*********************************************************
*About the Stata syntaxes:
*The do files contain Stata syntaxes. Datasets containing information on student borrowers are available only through restricted-use license from the United States Department of Education. 
*Contents of licensed files – such as variable statistics, variable descriptions, and numbers of observations – are protected by Section 183 of the Educational Sciences Reform Act of 2002. 
*Therefore, syntaxes related to variable names are redacted to a generic form. 

*Please see the "README" file for how to apply for the licensed data.
**********************************************************

*** Figure 1***
* The following generates Figure 1 and Table2 in one file

run "Main1.do"


*** Figure 2***
*Panel A
clear
use File8

preserve
keep if continuefb_id==1
tabstat distr out_dis_repayment dlq_after_loan [aw=$weight], c(s) s(N mean median sd p25 p75)
restore

preserve
keep if continuedefer_id==1 | continueIBR_id==1
tabstat distr out_dis_repayment  dlq_after_loan [aw=$weight], c(s) s(N mean median sd p25 p75)
restore

*Panel B, Subsequent Balance
clear
use File9

tabstat out_dis_offerdate if switch==1 [aw=$weight], by(post) c(s) s(N mean p50 semean)
tabstat out_dis_offerdate if switch==0 [aw=$weight], by(post) c(s) s(N mean p50 semean)


*** Figure 3***
clear
use File1

include Controls

foreach var of varlist continuefb_id continueIBR_id continuedefer_id{
replace `var'=0 if `var'==.
}

foreach var of varlist continuefb_id {
display "`var'"
reg `var' if female==1 [pw=$weight], level(90)
reg `var' if female==0 [pw=$weight], level(90)

reg `var' if white==1 [pw=$weight], level(90)
reg `var' if white==0 [pw=$weight], level(90)

reg `var' if femalewhite==1 [pw=$weight], level(90)
reg `var' if femalewhite==0 [pw=$weight], level(90)
}

foreach var of varlist continueIBR_id {
display "`var'"
reg `var' if female==1 [pw=$weight], level(90)
reg `var' if female==0 [pw=$weight], level(90)

reg `var' if white==1 [pw=$weight], level(90)
reg `var' if white==0 [pw=$weight], level(90)

reg `var' if femalewhite==1 [pw=$weight], level(90)
reg `var' if femalewhite==0 [pw=$weight], level(90)
}

foreach var of varlist continuedefer_id{
display "`var'"
reg `var' if female==1 [pw=$weight], level(90)
reg `var' if female==0 [pw=$weight], level(90)

reg `var' if white==1 [pw=$weight], level(90)
reg `var' if white==0 [pw=$weight], level(90)

reg `var' if femalewhite==1 [pw=$weight], level(90)
reg `var' if femalewhite==0 [pw=$weight], level(90)
}


*** Figure 4***
clear
use File1

include Controls

ivreg2 switch $control5 if white==1 [pw=$weight], cluster($cluster)
ivreg2 switch $control6 if white==1 [pw=$weight], cluster($cluster)

ivreg2 switch $control5 if white==0 [pw=$weight], cluster($cluster)
ivreg2 switch $control6 if white==0 [pw=$weight], cluster($cluster)

ivreg2 switch $control5 if female==1 [pw=$weight], cluster($cluster)
ivreg2 switch $control6 if female==1 [pw=$weight], cluster($cluster)

ivreg2 switch $control5 if female==0 [pw=$weight], cluster($cluster)
ivreg2 switch $control6 if female==0 [pw=$weight], cluster($cluster) 
